package com.hll.dao.role;

import com.hll.dao.BaseDao;
import com.hll.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: Mr.Hu
 * @create: 2021-03-08 15:07
 */
public class RoleDaoImpl implements RoleDao {

  @Override
  public List<Role> getRoleList(Connection connection) throws SQLException {
    PreparedStatement statement = null;
    List<Role> roles = null;
    ResultSet rs = null;
    if (connection != null) {
      String sql = "select * from smbms_role";
      Object[] params = {};
      rs = BaseDao.execute(connection, sql, statement, params); // 虽然没参数，也要传递空数组
      roles = new ArrayList<>();
      while (rs.next()) {
        Role _role = new Role();
        _role.setId(rs.getInt("id"));
        _role.setRoleCode(rs.getString("roleCode"));
        _role.setRoleName(rs.getString("roleName"));
        roles.add(_role);
      }

      BaseDao.release(null, statement, rs);
    }

    return roles;
  }
}
